<template>
	<view class="contain">
		<uni-forms :modelValue="formData">
					<uni-forms-item label="姓名" name="name">
						<uni-easyinput type="text" v-model="formData.nickName" placeholder="" />
					</uni-forms-item>
					<uni-forms-item label="邮箱" name="age">
						<input type="text" v-model="formData.email" placeholder="" />
					</uni-forms-item>
					<uni-forms-item label="电话" name="phone">
						<input type="text" v-model="formData.apperphonenumber" placeholder="" />
					</uni-forms-item>
					<uni-forms-item label="性别" name="sex">
						<input type="text" v-model="formData.sex" placeholder="" />
					</uni-forms-item>
					
		</uni-forms>
		<button @click="saving">保存</button>
	</view>
</template>

<script>
	import {getmyinfo,postmyinfo} from '@/utils/myinfo/index.js'
	export default {
		data() {
			return {
				formData:{
					idCard:"",
					sex:'0',
					nickName:"",
					age:"11",
					phonenumber:"123",
					apperphonenumber:"",
					email:""
				}
				
			}
		},
		onLoad() {
			this.gemyinfo()
			
			
		},
		methods: {
			// 发出请求信息
		async postmyinf(){
				this.formData.sex=this.formData.sex=="男"?'0':'1'
				// this.formData.phonenumber=this.formData.apperphonenumber.slice(-4)
				const res=await postmyinfo(this.formData)
				this.formData.sex=this.formData.sex==0?'男':'女'
				
			},
			// 发出获取信息渲染当页面
		async gemyinfo() {
			const res=await getmyinfo()
			console.log(res)
			this.$nextTick(()=>{
				this.formData=res.data.user
				this.formData.sex=this.formData.sex==0?'男':'女'
				this.formData.apperphonenumber=this.formData.phonenumber.slice(0,3)+"****"
			})
			},
			radio(x){
				console.log(x)
			},
			saving(){
				this.postmyinf()
				uni.showToast({
					icon:"success",
					title:"信息保存成功"
				})
				// this.gemyinfo()
			}
			
		}
	}
</script>

<style>
	.contain{
		width: 95%;
		margin: 20rpx auto;
	}

</style>
